///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include <iostream>
#include "combined.h"
#include "definitions.h"
#include "stringutil.h"
#include "world.h"

/*
 * This is where Symphony "boots"; you can specify a port and it starts
 * running the MUD on the specified port. Change DEFAULT_PORT (definitions.h)
 * to suit your desired default behavior.
 */

int main( int argc, char* argv[] ) {
	int port = DEFAULT_PORT;	// The port number the Server runs through.  We're just assuring a default value here.
	bool copyover = false;

	if ( argc >= 2 ) {
		if ( strstr( argv[1], "-copyover" ) ) {
			copyover = true;
			SocketServer::Instance().SetHostSocket( atoi( argv[2] ) );			     
		} else {
			// Check port number for validity...
			if ( atoi( argv[1] ) <= 1024 ) {	// Port too low...
				std::cout << "Ports below 1025 are reserved.  (You selected " << argv[1] << ")\n";
				exit( EXIT_PORT_TOO_LOW );
			} else if ( atoi( argv[1] ) >= 65000 ) {	// Port too high...
				std::cout << "Port must be below 65000.  (You selected " << argv[1] << ")\n";
				exit( EXIT_PORT_TOO_HIGH );
			} else { // The given port is usable...
				port = atoi( argv[1] );
			}
		}
	}

	// Set ourselves up for some randomness...
	srand( time( NULL ) );

	// Start the game...
	World::Instance().exist( "Symphony is ready to rock", port, copyover );

	return EXIT_NORMAL;
}
